import React, { useEffect, useState } from "react";
// import axios from "../../utils/request";
import { useLocation, useNavigate } from "react-router-dom";
import { Button, NavBar } from "antd-mobile";
import axios from "../../utils/request";

function Xq() {
  const { state } = useLocation();
  console.log(state);
  const navigate = useNavigate();

  const hua = async () => {
    // state.tick.vip
    const id = new Date().getTime();
    const res = await axios.get("/pay", {
      params: {
        title: "机票",
        id: id,
        price: 100,
      },
    });

    console.log(res);
    const lj = res.data.data;
    window.open(lj);

    const timer = setInterval(async () => {
      
      const res = await axios.get("/query", {
        params: {
          id: id,
        },
      });

      if (res.data.code == 200) {
        clearInterval(timer);
        navigate("/chengg");
      }
    }, 1000);
  };

  // console.log(id)
  return (
    <div>
      <NavBar>详情页面</NavBar>
      <dl
        style={{
          width: "100%",
          height: "80px",
          //   borderBottom: "1px solid #ccc",
          marginTop: "10px",
        }}
      >
        <dt>
          <div>
            {state.start} —— {state.end}
          </div>
          <div>{state.isSpeed ? "高铁" : "非高铁"}</div>
          <div>{state.isSeat ? "有票" : "无票"}</div>
        </dt>
        <dd>
          ￥：
          <span style={{ color: "red", fontWeight: "900" }}>
            {state.tick.vip}
          </span>
          <Button
            style={{ marginLeft: "230px" }}
            color="primary"
            onClick={() => {
              hua();
            }}
          >
            预定
          </Button>
        </dd>
      </dl>
    </div>
  );
}

export default Xq;
